package alogrithm;

import java.util.Arrays;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/9/10 21:54
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] a = new int[]{1, 4, 2, 5, 7, 8, 6, 9, 3};
        sort(a);
        System.out.println(Arrays.toString(a));
    }

    private static void sort(int[] a) {
        int n = a.length;
        for (int i = 0; i < n; ++i) {
            for (int j = i + 1; j < n; ++j) {
                if (a[j] < a[j - 1])
                    swap(a, j, j - 1);
            }
        }
    }

    private static void swap(int[] a, int j, int i) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
